package com.atguigu.product.controller;

import com.atguigu.product.entity.Product;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/product")
public class ProductController {

    @Value("${server.port:9000}")
    private String serverPort;

    @GetMapping("/{id}")
    public Product getProduct(@PathVariable Long id) {
        Product product = new Product();
        product.setId(id);

        // 给属性赋值
        product.setName("商品 —— " + id);
        product.setPrice(new BigDecimal("99.99"));
        product.setStock(100);

        return product;
    }

    @GetMapping("/info")
    public Map<String, Object> getInfo() {
        Map<String, Object> info = new HashMap<>();
        info.put("serviceName", "service-product");
        info.put("serverPort", serverPort);
        info.put("timestamp", System.currentTimeMillis());
        info.put("status", "UP");
        return info;
    }
}
